// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';

// 申明请求对象
const indexRequst = {
    BASE_URL: confing.QC_URL + "/index",

    //多选删除按钮
    deletes(indexIds,callback){
        //拼接URL
        let url=this.BASE_URL+"/deletes?t=1";
        if(indexIds !=undefined){
            indexIds.forEach(indexId =>{
                url +="&indexId="+indexId;
            })
          request.delete(url,callback);
        }
    },

    //删除信息
    delete(indexId, callback) {
        request.delete(this.BASE_URL + "/" + indexId, callback);
    },

    //保存信息
    save(index, callback) {
        if (index) {
            request.post(this.BASE_URL + "/save", index, callback);
        }
    },

    //根据id查询信息
    get(indexId, callback) {
        if (indexId) {
            // 准备url
            let url = this.BASE_URL + "/get?indexId=" + indexId;
            request.get(url, callback);
        }

    },


    //编辑信息
    edit(index, callback) {
        if (index != undefined && index.indexId != undefined) {
            request.put(this.BASE_URL + "/update", index, callback);
        }

    },


    // 请求的API
    list(page = 1, limit = 10, index, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page +
            "&limit=" + limit;
        if (index) {
            if (index.indexCode) {
                url += "&indexCode=" + index.indexCode;
            }
            if (index.indexName) {
                url += "&indexName=" + index.indexName;
            }
            if (index.indexType) {
                url += "&indexType=" + index.indexType;
            }
        }
        // 发送请求
        request.get(url, callbcak);
    }

}

// 将dictRequest暴漏出去
export default indexRequst;